package com.totoro.rpc.common.util;

import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by Niki on 2018/5/7 19:34
 */
@Slf4j
public class NetworkUtil {

    public static String getLocalAddress(int rpc_port) {
        return getLocalHostName() + ":" + rpc_port ;
    }

    private static String getLocalHostName()  {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            log.error("获取本机ip异常！",e);
        }
        return "127.0.0.1";
    }

    /**
     * 检查地址是否可达
     * @param address 需要检查的地址 ip:prot
     * @return
     */
    public static boolean serverHeath(String address) {
        return false;
    }

    private static int getLocalPort() {
        return 0;
    }
}
